

uni.addInterceptor('request', {
  invoke(args) {
    // request 触发前拼接 url
    args.url = 'http://apis.90000p.com/fkm/'+args.url
  },
 
})

 const http=(url,data,method='get')=>{
	 return new Promise((ok,no)=>{
		 uni.showLoading({
		 	title:'加载中'
		 })
		 uni.request({
		 	url,
			method,
			data,
			header:{
				Authorization:uni.getStorageSync('token')
			},
			success(val) {
				if(val.data.errCode==10000){
					ok(val.data)
				}else{
					uni.showToast({
						title:val.data.errMsg,
						icon:'error'
					})
					return no(val.data.errMsg)
				}
			},
			fail(val){
				if(val.errMsg=='request:fail'){
					uni.showToast({
						title:'网络错误,请重试',
						icon:'error'
					})
				}
			},
			complete(val){
				uni.hideLoading()
			}
		 })
	 })
 }
 
 const get = (url,data={})=>{
	 return http(url,data)
 }
 const post = (url,data={})=>{
 	 return http(url,data,'post')
 }
 
 export default {get,post}